package Proxy;

import java.util.Random;

interface Movable{
    void move();
}

/**
 * 记录Tank 移动花费了多少秒
 */
public class Tank implements Movable {
    public static void main(String[] args){
        System.out.println("tank move time");

//        Tank tank = new Tank();
//        tank.move();
        // 统计睡了多久
        // 方案2 怎么从外边切入进去
        Movable proxy = new LogTank(new TimeTankProxy(new Tank()));
        proxy.move();

        // TimeTankProxy 都是 切面, move 切点  静态代理 Movable proxy = new LogTank(new TimeTankProxy(new Tank()));
        // 可以理解 是从 Movable 这个面去切的 具体切的点是 move方法
    }

    @Override
    public void move() {
        long start = System.currentTimeMillis();
        System.out.println("ca....");
        try {
            Thread.sleep(new Random().nextInt(10000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();

        System.out.println("方案1,"+(end-start));
    }
}

/**
 * 日志代理坦克
 */
class LogTank implements Movable{
    private Movable m;
    public LogTank(Movable m){
        this.m = m;
    }
    @Override
    public void move() {
        System.out.println("loging");
        m.move();
    }
}